<template>
  <div>
    <div class="imglist_styl" v-if="imageList && imageList.length > 0">
      <div class="item_styl" v-for="(item, index) of imageList" :key="index" :style="{
        width,
        height
      }">
        <template>
          <img :src="imagePreviewUrl + item" />
          <div class="imgCover_styl">
            <div class="imgCoverContent_styl">
              <Icon type="ios-eye-outline" @click.native="handleView(item)"></Icon>
            </div>
          </div>
        </template>
      </div>
    </div>
    <div class="null_styl" v-else :style="{
      width, height
    }">
      <img src="@/assets/icon/nullimg.png" alt="">
      暂无图片
    </div>
    <PreviewImg v-if="isShowPreview" @listenChild="isShowPreview = false" :images="images"></PreviewImg>
  </div>
</template>
<script>
import PreviewImg from "@/components/qdPicUpload/previewImg"
import localData from "../../../localData";


export default {
  name: "imgReadOnly",
  components: {
    PreviewImg
  },
  props: {
    // 图片列表
    imageList: {
      type: Array,
      default: () => []
    },
    width: {
      type: String,
      default: "120px"
    },
    height: {
      type: String,
      default: "120px"
    }
  },
  data() {
    return {
      isShowPreview: false,
      images: "", // 要预览的图片
      imagePreviewUrl: localData.API_URl+'/guns',
    }
  },
  methods: {
    // 图片预览
    handleView(imgUrl) {
      this.images = imgUrl;
      this.isShowPreview = true;
    }
  }
}
</script> 
<style lang="less" scoped>
@import "~@/assets/styles/main.less";

.imglist_styl {
  .flex-x(flex-start, center);
  gap: 5px;

  .item_styl {
    position: relative;
    text-align: center;
    line-height: v-bind(height);
    border: solid 1px transparent;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);

    img {
      width: 100%;
      height: 100%;
    }

    .imgCover_styl {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      background: rgba(0, 0, 0, 0.6);
      width: 100%;
      height: 100%;

      display: none;

      .imgCoverContent_styl {
        width: 100%;
        height: 100%;
        .flex-x(center, center);
        gap: 2px;

        i {
          color: white;
          font-size: 20px;
          cursor: pointer;

        }

      }
    }

  }

  .item_styl:hover .imgCover_styl {
    display: block;
  }
}

.null_styl {
  border: solid 1px #e9eaeb;
  border-radius: 8px;
  color: #cecfcf;
  border-radius: 5px;
  background: #f7f8fc;
  font-size: 12px;
  .flex-y(center, center);
  gap: 2px;
  text-align: center;
}
</style>    